﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;

namespace AMStudio.Common
{
    internal class RuntimeTagDAL
    {
        /// <summary>
        /// 查询所有信息
        /// </summary>
        /// <returns></returns>
        public IList<RuntimeItem> SelectAllMapper()
        {
            var list = new List<RuntimeItem>();
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("MachineConfig");
            DataAccessor<RuntimeItem> myAccessor;
            myAccessor = db.CreateSqlStringAccessor("select * from [RTDB$]",
                MapBuilder<RuntimeItem>.MapAllProperties().
                Build()
                );
            list = myAccessor.Execute().ToList();
            return list;
        }

        public IDictionary<string, MachineInformationItem> GetAllErrors()
        {
            IDictionary<string, MachineInformationItem> list;
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("InformationList");
            DataAccessor<MachineInformationItem> myAccessor;
            myAccessor = db.CreateSqlStringAccessor("select * from [ERROR_LIST$]",
                MapBuilder<MachineInformationItem>.MapAllProperties().
                Build()
                );
            list = myAccessor.Execute().ToDictionary<MachineInformationItem, string>((item) =>
            {
                return item.Code;
            });
            return list;
        }

        public IDictionary<string, MachineInformationItem> GetAllConditions()
        {
            IDictionary<string, MachineInformationItem> list;
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("InformationList");
            DataAccessor<MachineInformationItem> myAccessor;
            myAccessor = db.CreateSqlStringAccessor("select * from [COND_LIST$]",
                MapBuilder<MachineInformationItem>.MapAllProperties().
                Build()
                );
            list = myAccessor.Execute().ToDictionary<MachineInformationItem,string>((item)=>
                {
                    return item.Code;
                });
            return list;
        }
        public IDictionary<string, MachineInformationItem> GetAllErrors_CN()
        {
            IDictionary<string, MachineInformationItem> list;
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("InformationList_CN");
            DataAccessor<MachineInformationItem> myAccessor;
            myAccessor = db.CreateSqlStringAccessor("select * from [ERROR_LIST$]",
                MapBuilder<MachineInformationItem>.MapAllProperties().
                Build()
                );
            list = myAccessor.Execute().ToDictionary<MachineInformationItem, string>((item) =>
            {
                return item.Code;
            });
            return list;
        }

        public IDictionary<string, MachineInformationItem> GetAllConditions_CN()
        {
            IDictionary<string, MachineInformationItem> list;
            Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("InformationList_CN");
            DataAccessor<MachineInformationItem> myAccessor;
            myAccessor = db.CreateSqlStringAccessor("select * from [COND_LIST$]",
                MapBuilder<MachineInformationItem>.MapAllProperties().
                Build()
                );
            list = myAccessor.Execute().ToDictionary<MachineInformationItem, string>((item) =>
            {
                return item.Code;
            });
            return list;
        }
    }
}
